<template>
  <div class="container">
    <el-dialog
      title="题目预览"
      :visible="showQsPreview"
      width="900px"
      @close="close"
      @open="open"
    >
      <el-row style="margin-bottom: 20px">
        <el-col :span="6">【题型】：{{ qsInfo.questionType | tx }}</el-col>
        <el-col :span="6">【编号】：{{ qsInfo.id }}</el-col>
        <el-col :span="6">【难度】：{{ qsInfo.difficulty | nd }}</el-col>
        <el-col :span="6">【标签】：{{ qsInfo.tags }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="6">【学科】：{{ qsInfo.subject }}</el-col>
        <el-col :span="6">【目录】：{{ qsInfo.catalog }}</el-col>
        <el-col :span="6">【方向】：{{ qsInfo.direction }}</el-col>
      </el-row>
      <el-divider></el-divider>
      【题干】：<div v-html="qsInfo.question" style="color:blue"></div>
       <div v-if="qsInfo.questionType!=='3'">
        <div style="padding-bottom:5px">{{qsInfo.questionType | tx}} 选项：（以下选中的选项为正确答案）</div>
        <div v-for="item in qsDetail.options" :key="item.code" style="padding:8px 0">
          <el-radio v-if="qsInfo.questionType==='1'" :value="item.isRight" :label="1">{{ item.title }}</el-radio>
          <el-checkbox v-if="qsInfo.questionType==='2'" :value="item.isRight?true:false" >{{ item.title }}</el-checkbox>
        </div>
      </div>
      <el-divider></el-divider>
      【参考答案】：<el-button type="danger" size="small" @click="preivewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="qsDetail.videoURL" controls></video>
      </div>
      <el-divider></el-divider>
      【答案解析】：<div style="display:inline-block" v-html="qsDetail.answer"></div>
      <el-divider></el-divider>
      【题目备注】：{{ qsDetail.remarks }}
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants'
import { detail } from '@/api/hmmm/questions'
export default {
  name: 'QsPreview-cy',
  props: {
    showQsPreview: {
      type: Boolean,
      default: false
    },
    qsInfo: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      qsDetail: {},
      play: false
    }
  },
  filters: {
    tx (value) {
      try {
        return questionType.find(item => item.value === +value).label + '题'
      } catch {
        return value
      }
    },
    nd (value) {
      try {
        return difficulty.find(item => item.value === +value).label
      } catch {
        return value
      }
    }
  },
  methods: {
    close () {
      this.play = false
      this.$refs.video.pause()
      this.$emit('update:showQsPreview', false)
    },
    async open () {
      try {
        const res = await detail({ id: this.qsInfo.id })
        this.qsDetail = res.data
      } catch {
        this.$message.error('接口坏了')
        this.qsDetail = {}
      }
    },
    preivewVideo () {
      this.play = true
      this.$refs.video.play()
    }
  }
}
</script>

<style scoped lang="less">
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
.video{
  width: 400px;
  height: 300px;
  video {
    width: 100%;
    height: 100%;
  }
}
</style>
